package com.wang.lotterysystem.common.config;


import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息队列使用路由模式
 */
@Configuration
public class DirectRabbitConfig {
    public static final String QUEUE_NAME = "DirectQueue";
    public static final String EXCHANGE_NAME = "DirectExchange";
    public static final String ROUTING = "DirectRouting";

    @Bean
    public DirectExchange directExchange(){ //创建交换机
        return ExchangeBuilder.directExchange(EXCHANGE_NAME).durable(true).build();
    }
    @Bean
    public Queue directQueue(){ //创建队列
        return QueueBuilder.durable(QUEUE_NAME).build();
    }
    @Bean
    public Binding directBinding(){
        return BindingBuilder.bind(directQueue()).to(directExchange()).with(ROUTING);
    }
    @Bean
    public MessageConverter jsonMessageConverter(){
        return new Jackson2JsonMessageConverter();
    }
}